package cn.uniqueww.javadesignpatterns.demos.design.template;


import lombok.Data;


/**
 * 爬虫抽象类
 *
 * @since 2024/1/17 11:35 上午
 */
@Data
public abstract class AbstractCrawler {

    /**
     * 打开网页
     */
    public void open() {
        System.out.println("打开网页");
    }


    /**
     * 爬取
     *
     * @param url
     * @return
     */
    public abstract String crawler(String url);

    /**
     * 解析
     *
     * @param content
     * @return
     */
    public abstract String parsing(String content);

    /**
     * 关闭网页
     */
    public void close() {
        System.out.println("关闭网页");
    }

    final public String crawlerTemplate(String url) {
        open();
        String content = crawler(url);
        String result = parsing(content);
        close();
        return result;
    }

}
